/*
 SearchFieldWithTip.m
 iSpeLL
 
 Created by liulei on 5/22/10.
 Copyright 2010 cool8jay@qq.com. All rights reserved.
 */

#import "SearchFieldWithTip.h"
#import "PreferenceController.h"

@implementation SearchFieldWithTip

- (void)awakeFromNib{
	[self addTrackingRect:[self bounds] 
					owner:self
				 userData:nil
			 assumeInside:YES];
}

#pragma mark -
#pragma mark Mouse Event

- (void)mouseEntered:(NSEvent *)theEvent
{
	BOOL showTip=[[NSUserDefaults standardUserDefaults] boolForKey:C8JShowTipKey];
	if(showTip){
		NSPoint buttonPoint = NSMakePoint(NSMidX([self frame]),
										  NSMidY([self frame]));
		
		NSPoint convertPoint=[[self window]convertBaseToScreen:buttonPoint];
		
		tipWindow=[[MAAttachedWindow alloc] initWithView:tipView 
										 attachedToPoint:convertPoint
											  atDistance:8.0];	
		[[self window] addChildWindow:tipWindow ordered:NSWindowAbove];
	}
}
- (void)mouseExited:(NSEvent *)theEvent
{
	BOOL showTip=[[NSUserDefaults standardUserDefaults] boolForKey:C8JShowTipKey];
	if(showTip){		
		[self removeTrackingRect:(NSTrackingRectTag)trackTag];
		[[self window] removeChildWindow:tipWindow];
		[tipWindow orderOut:self];
	}
}

@end
